





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>VTA Hardware Guide &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/translations.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../../../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../../../genindex.html" />
    <link rel="search" title="搜索" href="../../../search.html" />
    <link rel="next" title="VTA教程" href="../tutorials/index.html" />
    <link rel="prev" title="VTA配置" href="config.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../../../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../../../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html">
          

          
            
            <img src="../../../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../install/index.html">安装 TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../how_to/index.html">How To Guides</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../arch/index.html">Design and Architecture</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">VTA: Versatile Tensor Accelerator</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../install.html">VTA安装指南</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">VTA设计与开发指南</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="config.html">VTA配置</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">VTA Hardware Guide</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#vta-overview">VTA Overview</a></li>
<li class="toctree-l4"><a class="reference internal" href="#hls-hardware-source-organization">HLS Hardware Source Organization</a></li>
<li class="toctree-l4"><a class="reference internal" href="#architectural-overview">Architectural Overview</a></li>
<li class="toctree-l4"><a class="reference internal" href="#microarchitectural-overview">Microarchitectural Overview</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../tutorials/index.html">VTA教程</a></li>
<li class="toctree-l2"><a class="reference internal" href="../index.html#literature">Literature</a></li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../reference/langref/index.html">语言参考</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../reference/api/python/index.html">Python API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../reference/api/links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../reference/publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> <span class="br-arrow">></span></li>
        
          <li><a href="../index.html">VTA: Versatile Tensor Accelerator</a> <span class="br-arrow">></span></li>
        
          <li><a href="index.html">VTA设计与开发指南</a> <span class="br-arrow">></span></li>
        
      <li>VTA Hardware Guide</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../../../_sources/topic/vta/dev/hardware.rst.txt" rel="nofollow"> <img src="../../../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="vta-hardware-guide">
<h1>VTA Hardware Guide<a class="headerlink" href="#vta-hardware-guide" title="永久链接至标题">¶</a></h1>
<p>We present a top-down overview of the VTA hardware design.
This hardware design guide covers VTA hardware at two levels:</p>
<blockquote>
<div><ul class="simple">
<li><p>An architectural overview of the VTA design and its ISA hardware-software
interface.</p></li>
<li><p>A micro-architectural overview of the VTA hardware modules, and the
micro-code specification for the compute core.</p></li>
</ul>
</div></blockquote>
<div class="section" id="vta-overview">
<h2>VTA Overview<a class="headerlink" href="#vta-overview" title="永久链接至标题">¶</a></h2>
<p>VTA is a generic deep learning accelerator built for fast and efficient dense linear algebra.
VTA incorporates a simple RISC-like processor that can perform dense linear algebra operations on rank 1 or 2 tensor registers.
In addition the design adopts decoupled access-execute to hide memory access latency.</p>
<p>To a broader extent, VTA can serve as a template deep learning accelerator design for full stack optimization, exposing a generic tensor computation interface to the compiler stack.</p>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/blogpost/vta_overview.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/blogpost/vta_overview.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/blogpost/vta_overview.png" style="width: 80%;" /></a>
<p>The figure above gives a high-level overview of the VTA hardware organization.
VTA is composed of four modules that communicate among each other via FIFO queues and local memory blocks (SRAM), to enable task-level pipeline parallelism:</p>
<ul class="simple">
<li><p>The fetch module takes care of loading an instruction stream from DRAM. It also decodes those instructions to route them into one of three command queues.</p></li>
<li><p>The load module takes care of loading input and weight tensors from DRAM into data-specialized on-chip memories.</p></li>
<li><p>The compute module performs both dense linear algebra computation with its GEMM core, and general computation with its tensor ALU. It also takes care of loading data from DRAM into the register file, and loading micro-op kernels into the micro-op cache.</p></li>
<li><p>The store module stores results produced by the compute core back to DRAM.</p></li>
</ul>
</div>
<div class="section" id="hls-hardware-source-organization">
<h2>HLS Hardware Source Organization<a class="headerlink" href="#hls-hardware-source-organization" title="永久链接至标题">¶</a></h2>
<p>The VTA design is currently specified in Vivado HLS C++, which is only supported
by Xilinx toolchains.
The VTA hardware sources are contained under <code class="docutils literal notranslate"><span class="pre">3rdparty/vta-hw/hardware/xilinx/sources</span></code>:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">vta.cc</span></code> contains the definitions for each VTA module, as well as a top
level behavioral model for the top-level VTA design.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">vta.h</span></code> contains type definitions using Xilinx <code class="docutils literal notranslate"><span class="pre">ap_int</span></code> types, and
function prototypes declarations.</p></li>
</ul>
</div></blockquote>
<p>In addition preprocessor macros are defined under <code class="docutils literal notranslate"><span class="pre">3rdparty/vta-hw/include/vta/hw_spec.h</span></code>.
Much of these macro definitions are derived from the parameters listed in the
<code class="docutils literal notranslate"><span class="pre">3rdparty/vta-hw/config/vta_config.json</span></code> file.
The json file is processed by <code class="docutils literal notranslate"><span class="pre">3rdparty/vta-hw/config/vta_config.py</span></code> to produce a string of
compile flags that define the preprocessor macros.
That string is used by the makefile in order to set those high-level
parameters in both the HLS hardware synthesis compiler, and the C++
compiler that builds the VTA runtime.</p>
<div class="section" id="hls-module-example">
<h3>HLS Module Example<a class="headerlink" href="#hls-module-example" title="永久链接至标题">¶</a></h3>
<p>We show a definition of one of the VTA modules defined in C++:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span> <span class="nf">fetch</span><span class="p">(</span>
  <span class="kt">uint32_t</span> <span class="n">insn_count</span><span class="p">,</span>
  <span class="k">volatile</span> <span class="n">insn_T</span> <span class="o">*</span><span class="n">insns</span><span class="p">,</span>
  <span class="n">hls</span><span class="o">::</span><span class="n">stream</span><span class="o">&lt;</span><span class="n">insn_T</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">load_queue</span><span class="p">,</span>
  <span class="n">hls</span><span class="o">::</span><span class="n">stream</span><span class="o">&lt;</span><span class="n">insn_T</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">gemm_queue</span><span class="p">,</span>
  <span class="n">hls</span><span class="o">::</span><span class="n">stream</span><span class="o">&lt;</span><span class="n">insn_T</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">store_queue</span><span class="p">)</span> <span class="p">{</span>
<span class="cp">#pragma HLS INTERFACE s_axilite port = insn_count bundle = CONTROL_BUS</span>
<span class="cp">#pragma HLS INTERFACE m_axi port = insns offset = slave bundle = ins_port</span>
<span class="cp">#pragma HLS INTERFACE axis port = load_queue</span>
<span class="cp">#pragma HLS INTERFACE axis port = gemm_queue</span>
<span class="cp">#pragma HLS INTERFACE axis port = store_queue</span>
<span class="cp">#pragma HLS INTERFACE s_axilite port = return bundle = CONTROL_BUS</span>

  <span class="nl">INSN_DECODE</span><span class="p">:</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">pc</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">pc</span> <span class="o">&lt;</span> <span class="n">insn_count</span><span class="p">;</span> <span class="n">pc</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="cp">#pragma HLS PIPELINE II = 1</span>
    <span class="c1">// Read instruction fields</span>
    <span class="n">insn_T</span> <span class="n">insn</span> <span class="o">=</span> <span class="n">insns</span><span class="p">[</span><span class="n">pc</span><span class="p">];</span>
    <span class="c1">// Do some partial decoding</span>
    <span class="n">opcode_T</span> <span class="n">opcode</span> <span class="o">=</span> <span class="n">insn</span><span class="p">.</span><span class="n">range</span><span class="p">(</span><span class="n">VTA_INSN_MEM_0_1</span><span class="p">,</span> <span class="n">VTA_INSN_MEM_0_0</span><span class="p">);</span>
    <span class="n">memop_id_T</span> <span class="n">memory_type</span> <span class="o">=</span> <span class="n">insn</span><span class="p">.</span><span class="n">range</span><span class="p">(</span><span class="n">VTA_INSN_MEM_5_1</span><span class="p">,</span> <span class="n">VTA_INSN_MEM_5_0</span><span class="p">);</span>
    <span class="c1">// Push to appropriate instruction queue</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">opcode</span> <span class="o">==</span> <span class="n">VTA_OPCODE_STORE</span><span class="p">)</span> <span class="p">{</span>
      <span class="n">store_queue</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">insn</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">opcode</span> <span class="o">==</span> <span class="n">VTA_OPCODE_LOAD</span> <span class="o">&amp;&amp;</span>
        <span class="p">(</span><span class="n">memory_type</span> <span class="o">==</span> <span class="n">VTA_MEM_ID_INP</span> <span class="o">||</span> <span class="n">memory_type</span> <span class="o">==</span> <span class="n">VTA_MEM_ID_WGT</span><span class="p">))</span> <span class="p">{</span>
      <span class="n">load_queue</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">insn</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
      <span class="n">gemm_queue</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">insn</span><span class="p">);</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<dl>
<dt>A few observations on HLS coding:</dt><dd><ul>
<li><p><em>Parameters:</em> The parameter list of each function, combined with the
interface pragmas define the hardware interface exposed by the
generated hardware module.</p>
<blockquote>
<div><ul>
<li><p>Parameters passed by value indicate a read-only hardware memory-mapped
register that the host can write to.
This fetch function for instance has an <code class="docutils literal notranslate"><span class="pre">insn_count</span></code> parameter
which will be synthesized as a memory mapped register for the host
to write to, in order to set the length of a given VTA instruction
sequence.</p></li>
<li><p>Pointer parameters can mean one of two things depending on the interface
pragma being used.</p>
<blockquote>
<div><ul class="simple">
<li><p>When used with a <code class="docutils literal notranslate"><span class="pre">m_axi</span></code> interface pragma, an AXI master interface
gets generated to provide DMA access to DRAM.</p></li>
<li><p>When used with a <code class="docutils literal notranslate"><span class="pre">bram</span></code> interface pragma, a BRAM interface gets
generated to expose read and/or write ports to an FPGA block-RAM.</p></li>
</ul>
</div></blockquote>
</li>
<li><p>HLS streams being passed by reference combined with the <code class="docutils literal notranslate"><span class="pre">axis</span></code> interface
pragma produce FIFO interfaces to the module. Hardware FIFOs provide a
useful synchronization mechanism between modules.</p></li>
</ul>
</div></blockquote>
</li>
<li><p><em>Pragmas</em>: Compiler pragmas are essential to define hardware implementation
of each module. We list several pragmas used in the VTA design to communicate
implementation requirements to the compiler.</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">HLS</span> <span class="pre">INTERFACE</span></code>: specifies the interface of the synthesized
hardware module.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">HLS</span> <span class="pre">PIPELINE</span></code>: defines hardware pipeline performance target by setting
an initiation interval goal. When the <code class="docutils literal notranslate"><span class="pre">II</span> <span class="pre">==</span> <span class="pre">1</span></code> target is set, it tells
the compiler that the synthesized hardware pipeline should be able to
execute one loop iteration per cycle.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">HLS</span> <span class="pre">DEPENDENCE</span></code>: instructs the compiler to ignore certain types
of dependence checks in a given loop. Consider a loop body that writes
and reads to the same BRAM structure, and needs to achieve an II of 1.
The HLS compiler has to assume worst-case scenario, whereby a read is
issued to an address that a past write updated the cycle prior: this
cannot be achieved given BRAM timing characteristics (it takes at least
2 cycles to see the updated value). Therefore in order to achieve an II of 1,
the dependence checks have to be relaxed.
Note that when turning this optimization on, it falls onto
the software stack to prevent writes followed by reads to the same address.</p></li>
</ul>
</div></blockquote>
</li>
</ul>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>This <a class="reference external" href="https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug902-vivado-high-level-synthesis.pdf">reference guide</a>
provides a much more in-depth, and complete specification of HLS for the Xilinx 2018.2 toolchains.</p>
</div>
</dd>
</dl>
</div>
</div>
<div class="section" id="architectural-overview">
<h2>Architectural Overview<a class="headerlink" href="#architectural-overview" title="永久链接至标题">¶</a></h2>
<div class="section" id="instruction-set-architecture">
<h3>Instruction Set Architecture<a class="headerlink" href="#instruction-set-architecture" title="永久链接至标题">¶</a></h3>
<p>VTA’s instruction set architecture (ISA) is composed of 4 CISC instructions that have a variable execution latency, two of which execute a micro-coded instruction sequence to perform computation.</p>
<p>The VTA instructions are listed below:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">LOAD</span></code> instruction: loads a 2D tensor from DRAM into the input buffer, weight buffer, or register file. It can also load a micro-kernel into the micro-op cache. Supports dynamic padding when loading input and weight tiles.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">GEMM</span></code> instruction: performs a micro-op sequence of matrix-matrix multiplications over an input tensor and a weight tensors, and adds the result to a register-file tensor.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ALU</span></code> instruction: performs a micro-op sequence of matrix-matrix ALU operations over register-file tensor data.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">STORE</span></code> instruction: stores a 2D tensor from the output buffer to DRAM.</p></li>
</ul>
<p>The <code class="docutils literal notranslate"><span class="pre">LOAD</span></code> instructions are executed by the load and compute modules depending on the store memory buffer location target.
The <code class="docutils literal notranslate"><span class="pre">GEMM</span></code> and <code class="docutils literal notranslate"><span class="pre">ALU</span></code> instructions are executed by the compute module’s GEMM core and tensor ALU.
Finally, the <code class="docutils literal notranslate"><span class="pre">STORE</span></code> instructions are executed by the store module exclusively.
The fields of each instruction is described in the figure below.
The meaning of each field will be further explained in the <a class="reference internal" href="#vta-uarch"><span class="std std-ref">Microarchitectural Overview</span></a> section.</p>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/vta_instructions.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/vta_instructions.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/vta_instructions.png" style="width: 100%;" /></a>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>Note that the VTA ISA changes as VTA’s architectural parameters are modified (i.e. GEMM core shape, data type, memory size etc.), and as a result the ISA does not guarantee compatibility across all variants of VTA.
This is acceptable however, since the VTA runtime adapts to parameter changes, and produces binary code tailored for the version of the accelerator that gets generated.
This exemplifies the co-design philosophy adopted by the VTA stack which embraces fluidity of the hardware-software interface.</p>
</div>
</div>
<div class="section" id="dataflow-execution">
<h3>Dataflow Execution<a class="headerlink" href="#dataflow-execution" title="永久链接至标题">¶</a></h3>
<p>VTA relies on dependence FIFO queues between hardware modules to synchronize the execution of concurrent tasks.
The figure below shows how a given hardware module can execute concurrently from its producer and consumer modules in a dataflow fashion through the use of dependence FIFO queues, and single-reader/single-writer SRAM buffers.
Each module is connected to its consumer and producer via read-after-write (RAW) and write-after-read (WAR) dependence queues.</p>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/dataflow.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/dataflow.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/dataflow.png" style="width: 100%;" /></a>
<p>The pseudo-code above describes how a module executes a given instruction predicated on dependences with other instructions.
First, the dependence flags within each instruction are decoded in hardware.
If the instruction has an incoming RAW dependences, execution is predicated upon receiving a RAW dependence token from the producer module.
Similarly, if the task has an incoming WAR dependence, execution is predicated upon receiving a WAR dependence token from the consumer module.
Finally when the task is done, we check for outgoing RAW and WAR dependences, and notify the consumer and producer modules respectively.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>Note that the dependence tokens in this scenario are information-less.
This is because the instructions executed by each module cannot be reordered by design, as they arrive in FIFO order.</p>
</div>
</div>
<div class="section" id="pipeline-expandability">
<h3>Pipeline Expandability<a class="headerlink" href="#pipeline-expandability" title="永久链接至标题">¶</a></h3>
<p>The default VTA design is composed of four modules that describe a 3-stage <code class="docutils literal notranslate"><span class="pre">load-compute-store</span></code> task pipeline.
Following the dataflow hardware organization principle, we can extend VTA the pipeline to include more stages.
For example, we can envision separating the tensor ALU from the GEMM core in order to maximize the utilization of the GEMM core.
This would result in a <code class="docutils literal notranslate"><span class="pre">load-gemm-activate-store</span></code> task pipeline which closely reflects the TPU design.
Adding more stages has a cost however: it can add storage and extra logic overhead, which is why we opted for a default 3-stage pipeline.</p>
</div>
</div>
<div class="section" id="microarchitectural-overview">
<span id="vta-uarch"></span><h2>Microarchitectural Overview<a class="headerlink" href="#microarchitectural-overview" title="永久链接至标题">¶</a></h2>
<p>We describe the modules that compose the VTA design.
The module definitions are contained in <code class="docutils literal notranslate"><span class="pre">3rdparty/vta-hw/hardware/xilinx/sources/vta.cc</span></code>.</p>
<div class="section" id="fetch-module">
<h3>Fetch Module<a class="headerlink" href="#fetch-module" title="永久链接至标题">¶</a></h3>
<p>VTA is programmed by a linear instruction stream.
The fetch module is the entry point of VTA to the CPU and is programmed via three memory mapped registers:</p>
<ul class="simple">
<li><p>The read-write <code class="docutils literal notranslate"><span class="pre">control</span></code> register starts the fetch module, and is read to check for its completion.</p></li>
<li><p>The write-only <code class="docutils literal notranslate"><span class="pre">insn_count</span></code> register sets the number of instructions to execute.</p></li>
<li><p>The write-only <code class="docutils literal notranslate"><span class="pre">insns</span></code> register sets the start address of the instruction stream in DRAM.</p></li>
</ul>
<p>The CPU prepares the instruction stream in DRAM in a physically-contiguous buffer prepared by the VTA runtime.
When the instruction stream is ready, the CPU writes the start physical address into the <code class="docutils literal notranslate"><span class="pre">insns</span></code> register, the length of the instruction stream into the <code class="docutils literal notranslate"><span class="pre">insn_count</span></code> register, and asserts the start signal in the <code class="docutils literal notranslate"><span class="pre">control</span></code> register.
This procedure starts VTA, which reads in the instruction stream from DRAM via DMA.</p>
<p>Upon accessing the instruction stream, the fetch module partially decodes instructions, and pushes those instructions into command queues that feed into the load, compute, and store modules:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">STORE</span></code> instructions are pushed to the store command queue to be processed by the store module.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">GEMM</span></code> and <code class="docutils literal notranslate"><span class="pre">ALU</span></code> instructions are pushed to the compute command queue to be processed by the compute module.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LOAD</span></code> instructions that describe a load operation of micro-op kernels or register file data are pushed to the compute command queue to be processed by the compute module.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LOAD</span></code> instructions that describe a load operation of input or weight data are pushed to the load command queue to be processed by the load module.</p></li>
</ul>
<p>When one of the command queues becomes full, the fetch module stalls until the queue is not full.
Consequently, the command queues are sized to be deep enough to allow for a wide execution window, and allow multiple tasks to be in flight concurrently across the <code class="docutils literal notranslate"><span class="pre">load-compute-store</span></code> pipeline.</p>
</div>
<div class="section" id="compute-module">
<h3>Compute Module<a class="headerlink" href="#compute-module" title="永久链接至标题">¶</a></h3>
<p>VTA’s compute module acts as a RISC processor that performs computation on tensor registers rather than scalar registers.
Two functional units mutate the register file: the tensor ALU, and the GEMM core.</p>
<p>The compute module executes RISC micro-ops from the micro-op cache.
There are two types of compute micro-ops: ALU and GEMM operations.
To minimize the footprint of micro-op kernels, while avoiding the need for control-flow instructions such as conditional jumps, the compute module executes micro-op sequences inside a two-level nested loop that computes the location of each tensor register location via an affine function.
This compression approach helps reduce the micro-kernel instruction footprint, and applies to both matrix multiplication and 2D convolution, commonly found in neural network operators.</p>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/gemm_core.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/gemm_core.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/gemm_core.png" style="width: 100%;" /></a>
<p>The <strong>GEMM core</strong> evaluates GEMM instructions, by executing a micro-code sequence in a 2-level nested loop described in the Figure above.
The GEMM core can perform one input-weight matrix multiplication per cycle.
The dimensions of the single-cycle matrix multiplication defines a hardware <em>tensorization intrinsic</em> which the TVM compiler has to lower a computation schedule onto.
This tensorization intrinsic is defined by the dimensions of the input, weight and accumulator tensors.
Each data type can have a different integer precision: typically both weight and input types are low-precision (8-bits or less), while the accumulator tensor has a wider type to prevent overflows (32-bits).
In order to keep the GEMM core busy, each of the input buffer, weight buffer, and register file have to expose sufficient read/write bandwidth.</p>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/alu_core.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/alu_core.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/alu_core.png" style="width: 100%;" /></a>
<p>The <strong>Tensor ALU</strong> supports a set of standard operations to implement common activation, normalization, and pooling operators.
VTA being a modular design, the range of operators that the Tensor ALU supports can be extended for higher operator coverage, at the expense of higher resource utilization.
The Tensor ALU can perform tensor-tensor operations, as well as tensor-scalar operations on an immediate value.
The opcode of the tensor ALU, and the immediate value are specified by the high-level CISC instruction.
The micro-code in the context of tensor ALU computation only takes care of specifying data access patterns.</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>In terms of computational throughput, the Tensor ALU does not execute at a rate of one operation per cycle.
The limitation comes from the lack of read-ports: since one register file tensor can be read per cycle, the tensor ALU has an initiation interval of at least 2 (i.e. performs at most 1 operation every 2 cycles).
In addition, performing a single tensor-tensor operation at once can be expensive especially given that register file types are wide, typically 32-bit integers.
As a result, in order to balance the resource utilization footprint of the Tensor ALU with the GEMM core, a tensor-tensor operation is by default performed via vector-vector operations over multiple cycles.</p>
</div>
</div>
<div class="section" id="load-and-store-modules">
<h3>Load and Store Modules<a class="headerlink" href="#load-and-store-modules" title="永久链接至标题">¶</a></h3>
<a class="reference internal image-reference" href="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/2d_dma.png"><img alt="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/2d_dma.png" class="align-center" src="https://raw.githubusercontent.com/uwsampl/web-data/main/vta/developer/2d_dma.png" style="width: 100%;" /></a>
<p>The load and store modules perform 2D DMA loads with a strided access pattern from DRAM to SRAM.
In addition, the load module can insert 2D padding on the fly, which is useful when blocking 2D convolution.
This means that VTA can tile 2D convolution inputs without paying the overhead of re-laying data out in DRAM to insert spatial padding around input and weight tiles.</p>
</div>
</div>
</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../tutorials/index.html" class="btn btn-neutral float-right" title="VTA教程" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="config.html" class="btn btn-neutral float-left" title="VTA配置" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../../../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>